home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
intrvews
/
xgrab.lha
/
xgrab
/
ui
/
fonthandler.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-06
|
5KB
|
195 lines
/**
GRAB Graph Layout and Browser System
Copyright (c) 1989, Tera Computer Company
**/
/**
Handler for font information for the xgrab window, including the
node and edge labels, and for postscript output.
There are six fonts used for node and edge labels in the xgrab
window. From largest to smallest:
new century schoolbook 12pt
new century schoolbook 10pt
helvetica 10pt
new century schoolbook 8pt
helvetica 8pt
times 8pt
The helvetica fonts are skinnier than new century, and the times is
even skinnier.
'stdfont' is used for text in other parts of the xgrab window. The
postscript routines have their own default font.
As the size of the nodes grows and shrinks on the screen, the program
attempts to change the font so that the node labels fit inside the
nodes. The edge labels are never bigger than the node labels. The
file contains routines to set the fonts, find the size of a string
in a given font, and so on.
**/
#include "fonthandler.h"
#include <stdio.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
/**
The following numbers are lies in that the fonts aren't really this
big (they certainly aren't bigger). True widths can't be given
since all the fonts are variable width. True heights could be given,
but then we'd end up seeing the same fonts over and over and it'd
be really tedious.
The font names are found in /usr/lib/X11/fonts/75dpi/fonts.dir
**/
static int Font_Widths[numberfonts] = { 12, 10, 9, 8, 7, 6};
static int Font_Heights[numberfonts] = { 22, 16, 16, 16, 13, 10};
static char *Font_Names[numberfonts] =
{
"-adobe-new century schoolbook-medium-r-normal--12-120-75-75-p-70-iso8859-1",
"-adobe-new century schoolbook-medium-r-normal--10-100-75-75-p-60-iso8859-1",
"-adobe-helvetica-medium-r-normal--10-100-75-75-p-56-iso8859-1",
"-adobe-new century schoolbook-medium-r-normal--8-80-75-75-p-50-iso8859-1",
"-adobe-helvetica-medium-r-normal--8-80-75-75-p-46-iso8859-1",
"-adobe-times-medium-r-normal--8-80-75-75-p-44-iso8859-1"
};
FontHandler::FontHandler()
/**
The fonthandler keeps track of the current edge, node, text and
postscript output fonts and whether node and edge labels are forced
**/
{
int i;
/**
The edge label map array tells which font to use for a given
node font. In general, use the one 3 smaller than this one, unless
there is no such font, in which case use the smallest one
**/
for (i = 0; i < numberfonts; i++)
{
FontArray[i] = new Font(Font_Names[i]);
EdgeLabelMapArray[i] = MIN(i+3, numberfonts-1);
}
newScreen();
text_flag = true;
nlabel_forced = false;
elabel_forced = false;
psfont = nil;
}
void FontHandler::SetPS(char* name)
/* Set the postscript output font */
{
psfont = new Font(name);
}
int FontHandler::WidthPS(char* str)
/* Find the width of a string in the postscript font */
{
return psfont->Width(str);
}
void FontHandler::newScreen()
{
text_font = stdfont;
node_font = FontArray[startfont];
edge_font = FontArray[EdgeLabelMapArray[startfont]];
}
void FontHandler::set_fonts(int font_num)
{
node_font = FontArray[font_num];
edge_font = FontArray[EdgeLabelMapArray[font_num]];
}
void FontHandler::set_font(int sizex, int sizey)
/* set the font to the one no larger than sizex X sizey */
{
int i, j;
text_flag = true; /* assume can draw text */
for (i = 0; i < numberfonts; i++)
{
if (sizex >= Font_Widths[i])
{
break;
}
}
for (j = i; j < numberfonts; j++)
{
if (sizey >= Font_Heights[j])
{
break;
}
}
if (j >= numberfonts)
{
text_flag = false;
/**
set to smallest font in case we want to force
the printing of the labels
**/
set_fonts(numberfonts - 1);
}
else
{
set_fonts(j);
}
}
boolean FontHandler::FontWillFit(int sizex, int sizey)
/* return true if there is a font which is smaller than sizex X sizey */
{
int i;
for (i = 0; i < numberfonts; i++)
{
if ((sizex >= Font_Widths[i]) && (sizey >= Font_Heights[i]))
{
break;
}
}
if (i >= numberfonts)
{
return false;
}
else
{
return true;
}
}
void FontHandler::force_nlabel()
{
nlabel_forced = true;
}
void FontHandler::noforce_nlabel()
{
nlabel_forced = false;
}
void FontHandler::force_elabel()
{
elabel_forced = true;
}
void FontHandler::noforce_elabel()
{
elabel_forced = false;
}
void FontHandler::SmallestFont(int* width, int* height)
/* return the size of the smallest font */
{
*width = Font_Widths[numberfonts - 1];
*height = Font_Heights[numberfonts - 1];
}